Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid having to go back to the UI thread in the navbar code #73681

Merged
merged 6 commits into from
May 24, 2024

Conversation

CyrusNajmabadi
Copy link
Member

No description provided.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels May 23, 2024
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review May 24, 2024 00:16
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 24, 2024 00:16
@CyrusNajmabadi
Copy link
Member Author

@ToddGrun ptal

@@ -161,26 +183,6 @@ void IDisposable.Dispose()
_cancellationTokenSource.Cancel();
}

private void Pause()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inlined these.


// Cancel any in flight work. We're on the UI thread, so we know this is the latest position of the user, and that
// this should supersede any other selection work items.
_selectItemQueue.AddWork(caretPoint.Value, cancelExistingWork: true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we now grab the caret and pass it along.

{
// Switch to the UI so we can determine where the user is and determine the state the last time we updated
// the UI.
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken).NoThrowAwaitable();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more need to switch here.


GetProjectItems(out var projectItems, out var selectedProjectItem);
var (projectItems, selectedProjectItem) = GetProjectItems();
if (Equals(model, lastPresentedInfo.model) &&
Equals(currentSelectedItem, lastPresentedInfo.selectedInfo) &&
Equals(selectedProjectItem, lastPresentedInfo.selectedProjectItem) &&
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the common case (caret moving in the same member) we will bail out immediately, and not hit hte ui thread. we only need to go back if we're actually updating the UI thread.

// Once we've computed and selected the latest navbar items, pause ourselves if we're no longer visible.
// That way we don't consume any machine resources that the user won't even notice.
if (_visibilityTracker?.IsVisible(_subjectBuffer) is false)
Pause();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was intentionally removed. we don't need to check this here for visibility. We just listen for visbility changes directly and pause/unpause us accordingly.

language: d.Project.Language)).OrderBy(projectItem => projectItem.Text)];
language: d.Project.Language))
.OrderBy(projectItem => projectItem.Text)
.ToImmutableArray();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToImmutableArray

nice catch here. One of Linq's best abilities is hiding extra sorts.

Pause();
}
// Make a task that waits indefinitely, or until the cancellation token is signaled.
var cancellationTriggeredTask = Task.Delay(-1, cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task.Delay(-1, cancellationToken);

Weird, this seems like a common enough desire that I would have thought there would be something like a CancellationToken.ToTask() method or equivalent somewhere to hide the backing Task.Delay(-1, ...).

@ToddGrun
Copy link
Contributor

I'm very happy with this change. I feel like mainthread switches are an area that we've neglected in our perf efforts.

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants